package com.example.projectdemo.bottomappbar;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.projectdemo.R;
import com.google.android.material.bottomappbar.BottomAppBar;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

/***
 * 创建时间：2020/2/26 14:37
 * 创建人：10850
 * 功能描述：https://github.com/986244073/yancy-Android-BottomAppBar
 * https://www.jianshu.com/p/20dbe17d8c91
 * https://www.jianshu.com/p/7015c8554299
 */
public class BABActivity extends AppCompatActivity {

    BottomAppBar bottomAppBar;
    Button materialButton;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_baba);


        bottomAppBar = findViewById(R.id.bottom_appbar);
        materialButton = findViewById(R.id.materialButton);

        //setSupportActionBar(bottomAppBar);

        bottomAppBar.setNavigationIcon(android.R.drawable.ic_menu_zoom);
        bottomAppBar.setNavigationContentDescription(android.R.string.search_go);
        bottomAppBar.setContentInsetStartWithNavigation(0);
        bottomAppBar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(BABActivity.this, "navigationIcon", Toast.LENGTH_SHORT).show();
            }
        });

        bottomAppBar.replaceMenu(R.menu.my_menu);
        bottomAppBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.next_btn:
                        Toast.makeText(BABActivity.this, "下一个", Toast.LENGTH_SHORT).show();
                        return true;
                    case R.id.action_settings:
                        Toast.makeText(BABActivity.this, "设置", Toast.LENGTH_SHORT).show();
                        return true;
                    case R.id.action_notification:
                        Toast.makeText(BABActivity.this, "通知", Toast.LENGTH_SHORT).show();
                        return true;
                }
                return false;
            }
        });

        materialButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (bottomAppBar.getFabAlignmentMode() == BottomAppBar.FAB_ALIGNMENT_MODE_CENTER)
                    bottomAppBar.setFabAlignmentMode(BottomAppBar.FAB_ALIGNMENT_MODE_END);
                else {
                    bottomAppBar.setFabAlignmentMode(BottomAppBar.FAB_ALIGNMENT_MODE_CENTER);
                }
            }
        });
    }
}
